//
//  LEOpenPickerTool.m
//  LoveExpressBusiness
//
//  Created by 刘甲奇 on 2017/5/12.
//  Copyright © 2017年 DFH. All rights reserved.
//

#import "LEOpenPickerTool.h"

@interface LEOpenPickerTool()

@end

@implementation LEOpenPickerTool

+ (void)openPickerView:(UIViewController *)viewController
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择照片来源" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
         [self openLibrary:viewController];
        
    }];
    
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self openCamera:viewController];
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alert addAction:action];
    [alert addAction:action1];
    [alert addAction:action2];
    [viewController presentViewController:alert animated:YES completion:nil];

}
/**
 打开本地相册
 */
+ (void)openLibrary:(UIViewController *)viewController
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = viewController;
    picker.allowsEditing = YES;
    
    [viewController presentViewController:picker animated:YES completion:nil];
}
/**
 开始拍照
 */
+ (void)openCamera:(UIViewController *)viewController
{
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = viewController;
        //设置拍照后的图片可被编辑
        picker.allowsEditing = YES;
        picker.sourceType = sourceType;
        
        [viewController presentViewController:picker animated:YES completion:nil];
        
    }else
    {
        NSLog(@"模拟其中无法打开照相机,请在真机中使用");
    }
}


@end











